<?php

class TableObject {
	
	public $columns;
	public $tableName;
}

class TempObject{
	public $flag;
	public $index;
	public $tables;
}

require "configs/smartmain.php";
require "configs/Mysql.class.php";
include_once 'DescTableFunction.php';

session_start ();
$tables = array ();
$tempTables = array ();
$totalTables = $_REQUEST ["totalTableSize"];
$lastTableName="";
for($i1 = 0, $i2 = 0; $i1 < $totalTables; $i1 ++) {
	$tn = "mTableName" . $i1;
	//echo $tn."<br //>";
	if (isset ( $_REQUEST [$tn] )) {
		$newt = new TableObject ( );
		$newt->tableName = $_REQUEST [$tn];
		$newt->columns = GetTableDesc ( $newt->tableName );
		$tables [] = $newt;
		if ($i2 == 0) {
			$tt=new TempObject();
			$tt->flag=0;
			$tt->index=$i2;
			$tempTables [] =$tt;
		}
		else {
			$tt=new TempObject();
			$tt->flag=1;
			$tt->index=$i2;
			$tt->tables=array();
			
			$tt->tables[]=$lastTableName;
			$tt->tables[]=$newt->tableName;
			$tempTables [] =$tt;
			
			$tt=new TempObject();
			$tt->flag=0;
			$tt->index=$i2;
			$tempTables [] =$tt;
		}
		$i2 ++;
		$lastTableName=$newt->tableName;
		
	}
}

dd($tables,'$tables');
//echo count($tableNames)."<br //>";


if (isset ( $_REQUEST ["exTSize"] )) {
	for($i1 = 0; $i1 < intval ( $_REQUEST ["exTSize"] ); $i1 ++, $i2 ++) {
			if ($i2 == 0) {
			$tt=new TempObject();
			$tt->flag=0;
			$tt->index=$i2;
			$tempTables [] =$tt;
		}
		else {
			$tt=new TempObject();
			$tt->flag=1;
			$tt->index=$i2;
			$tempTables [] =$tt;
			$tt=new TempObject();
			$tt->flag=0;
			$tt->index=$i2;
			$tempTables [] =$tt;
		}
	}
}


$template->assign ( "tables", $tables );
$template->assign ( "tableSize", count ( $tables ) );
$template->assign ( "tempTables", $tempTables );

$template->display ( 'ArrangeTables.tpl.html' );

?>
